﻿<?php
	
	$inConn = mysql_connect('localhost','root','') or die('mysql conn faied:'.mysql_error() );
	
	//mysql_select_db('info_pust',$conn);
	mysql_select_db('info_push',$inConn);
	mysql_query("set names utf8");	
	
	if(empty($_POST['title']))
		ShowInfo('title can\'t empty',$_SERVER['HTTP_REFERER'],0,3000);
	if(empty($_POST['content']))
		ShowInfo('content can\'t empty',$_SERVER['HTTP_REFERER'],0,3000);
		

	if($_POST['dopost']=='add')
	{
		$insertQuery = "insert into `push`(`title`, `gameName`, `content`) values ('{$_POST['title']}','{$_POST['gameName']}','{$_POST['content']}') ";
		
		try{
			$inResult = mysql_query($insertQuery,$inConn) or die('insertQuery failed:'.mysql_error());
			ShowInfo('插入记录成功.',$_SERVER['HTTP_REFERER'],0,3000);
		}catch(Exception $e)
		{
			$msg="错误：插入SQL 语句失败.".$e;
			ShowInfo($msg,$_SERVER['HTTP_REFERER'],0,3000);
		}
		//echo $inResult;
		
	}	
	else if($_POST['dopost']=='edit')
	{		
		$query = "UPDATE `push` SET 
					`title`='{$_POST['title']}'
					,`gameName`='{$_POST['gameName']}'
					,`content`='{$_POST['content']}' 
				  WHERE `id`={$_POST['id']}";
				  
		try{
			$result = mysql_query($query,$inConn) or die('update query failed:'. mysql_error());
			if($result==1){
				ShowInfo('修改成功',$_SERVER['HTTP_REFERER'],0,3000);exit();
				//header("location:{$_SERVER['HTTP_REFERER']}");
			}
		}catch(Exception $e)
		{
			$msg='错误：执行SQL语句失败。'.$e;
			ShowInfo($msg,$_SERVER['HTTP_REFERER'],0,3000);
		}
	
	}
	else if($_POST['dopost']=='delete'){		
		try{
			$result = mysql_query("delete from push where id = {$_POST['id']}",$inConn) or die('update query failed:'. mysql_error());
			if($result==1){
				ShowInfo('修改成功',$_SERVER['HTTP_REFERER'],0,3000);exit();
				//header("location:{$_SERVER['HTTP_REFERER']}");
			}
		}catch(Exception $e)
		{
			$msg='错误：执行SQL语句失败。'.$e;
			ShowInfo($msg,$_SERVER['HTTP_REFERER'],0,3000);
		}
	}
	
	function ShowInfo($msg, $gourl, $onlymsg=0, $limittime=0)
	{
		if(empty($GLOBALS['cfg_plus_dir'])) $GLOBALS['cfg_plus_dir'] = '..';

		$htmlhead  = "<html>\r\n<head>\r\n<title>TENONE 提示信息</title>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n";
		$htmlhead .= "<base target='_self'/>\r\n<style>div{line-height:160%;}</style></head>\r\n<body leftmargin='0' topmargin='0' bgcolor='#FFFFFF'>".(isset($GLOBALS['ucsynlogin']) ? $GLOBALS['ucsynlogin'] : '')."\r\n<center>\r\n<script>\r\n";
		$htmlfoot  = "</script>\r\n</center>\r\n</body>\r\n</html>\r\n";

		$litime = ($limittime==0 ? 1000 : $limittime);
		$func = '';

		if($gourl=='-1')
		{
			if($limittime==0) $litime = 5000;
			$gourl = "javascript:history.go(-1);";
		}

		if($gourl=='' || $onlymsg==1)
		{
			$msg = "<script>alert(\"".str_replace("\"","“",$msg)."\");</script>";
		}
		else
		{
			//当网址为:close::objname 时, 关闭父框架的id=objname元素
			if(preg_match('/close::/',$gourl))
			{
				$tgobj = trim(preg_replace('/close::/', '', $gourl));
				$gourl = 'javascript:;';
				$func .= "window.parent.document.getElementById('{$tgobj}').style.display='none';\r\n";
			}
			$func .= "      var pgo=0;
      function JumpUrl(){
        if(pgo==0){ location='$gourl'; pgo=1; }
      }\r\n";

			$rmsg = $func;
			$rmsg .= "document.write(\"<br /><div style='width:450px;padding:0px;border:1px solid #DADADA;'>";
			$rmsg .= "<div style='padding:6px;font-size:12px;border-bottom:1px solid #DADADA;background:#DBEEBD url({$GLOBALS['cfg_plus_dir']}/img/wbg.gif)';'><b>TENONE 提示信息！</b></div>\");\r\n";
			$rmsg .= "document.write(\"<div style='height:130px;font-size:10pt;background:#ffffff'><br />\");\r\n";
			$rmsg .= "document.write(\"".str_replace("\"","“",$msg)."\");\r\n";
			$rmsg .= "document.write(\"";

			if($onlymsg==0)
			{
				if( $gourl != 'javascript:;' && $gourl != '')
				{
					$rmsg .= "<br /><a href='{$gourl}'>如果你的浏览器没反应，请点击这里...</a>";
					$rmsg .= "<br/></div>\");\r\n";
					$rmsg .= "setTimeout('JumpUrl()',$litime);";
				}
				else
				{
					$rmsg .= "<br/></div>\");\r\n";
				}
			}
			else
			{
				$rmsg .= "<br/><br/></div>\");\r\n";
			}
			$msg  = $htmlhead.$rmsg.$htmlfoot;
		}
		echo $msg;
	}
	
?>